﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lm.Common.Auth.Account
{
    class AccountValidator
    {
        public Model.Account Validate(Guid accountId)
        {
            if (accountId == null)
            { throw new Exception("帐号Id不能为空"); }
            using (var tran = new System.Transactions.TransactionScope())
            {
                var helper = DAL.DALFactory.Create();
                if (helper.IsSingle<Model.Account>(t => t.Id == accountId) == false)
                { throw new Exception("帐号不存在"); }
                var account = helper.GetSingle<Model.Account>(t => t.Id == accountId);
                if (account.Status != Model.AccountStatus.Live.ToString())
                { throw new Exception("帐号不是可用状态"); }
                if (account.Pause)
                { throw new Exception("帐号处于暂停状态"); }
                tran.Complete();
                return account;
            }
        }
    }
}
